<?php
class dash extends adminBase {
    function __construct() {
        parent::__construct();
        $this->cms->setPageTitle("管理面板");
    }

    function indexTask(){
        $this->cms->setActionTitle("概要总览");
        $admin = AdminModule::init('admin');
        $admin_info = $admin->getDetail($this->user->getLoginInfo()['id']);
        $db=SqlDB::init();
        //获取用户量
        $result['user_total']=$db->getValue("SELECT count(*) FROM `user_info`");
        //获取商家量
        $shop_sql = "SELECT count(*) FROM `shop_info` WHERE `enable`=1 and `site_id`=?";
        $result['shop_total']=$db->getValue($shop_sql,$admin_info['site_id']);
        //获取商品量
        $goods_sql = "SELECT count(*) FROM `goods` WHERE `enable`=1 and `site_id`=?";
        $result['goods_total']=$db->getValue($goods_sql,$admin_info['site_id']);
        //获取服务站量
        $service_sql = "SELECT count(*) FROM `service_info`WHERE `enable`=1 and `site_id`=?";
        $result['service_total']=$db->getValue($service_sql,$admin_info['site_id']);
        //获取总成交量
        $order_sql = "SELECT sum(`order_amount`) FROM `order` where `state`<>'unpaid' and `site_id`=?";
        $result['order_total']=$db->getValue($order_sql,$admin_info['site_id']);
        //获取本月日均交易额
        $todayDate=date("Y-m-d");
        $beginDate=date('Y-m-d', mktime(0,0,0,date('n'),1,date('Y')));
//        $endDate=date('Y-m-d', mktime(0,0,0,date('n'),date('t'),date('Y')));
        if($todayDate==$beginDate){
            $days = 1;
        }else{
            $days=round((strtotime($todayDate)-strtotime($beginDate))/3600/24);
        }
        $sql="SELECT sum(`order_amount`) FROM `order` where `payment_time`>=? and `payment_time`<? and `site_id`=?";
        $result['this_month']=$db->getValue($sql,$beginDate,$todayDate,$admin_info['site_id']);
        //获取本月日均交易额
        $result['average_month']=round($result['this_month']/$days,2);
        //获取当日交易额
        $tomorrowDate=date("Y-m-d",strtotime("+1 day"));
        $result['order_today']=$db->getValue($sql, $todayDate, $tomorrowDate,$admin_info['site_id']);
        $sql_getSiteName = "SELECT `name` FROM `admin`,`site` where `admin`.`id`=? and `site`.`id`=`admin`.`site_id`";
        $result['site_name']=$db->getValue($sql_getSiteName,$this->user->getLoginInfo()['id']);
        $this->cms->tableScene($result,"admin/tpl/table.php");
    }
}